<template>
    <div id="app">
        <router-view/>
        <com-nav v-show="show_nav" :routeName="routeName"></com-nav>
    </div>
</template>

<script>
    import comNav from './components/nav'

    export default {
        components: {comNav},
        data() {
            return {
                routeName: '',
                show_nav: true,

            }
        },
        created() {
            this.init()
        },
        methods: {
            GetQueryString(name) {
                const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
                const r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            },
            init() {
                let timestamp = new Date().getTime();
                let nonce = '1341afaf'
                this.$get('/api/wx/share1').then(res => {
                    this.$get('/api/wx/share2', {params: {token: res.data.access_token}}).then(res => {
                        this.$get('/api/wx/share3', {
                            params: {
                                jsapi_ticket: res.data.ticket, url: window.location.href
                            }
                        }).then(rr => {
                            wx.config({
                                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                                appId: rr.data.oppId, // 必填，公众号的唯一标识
                                timestamp: rr.data.timestamp, // 必填，生成签名的时间戳
                                nonceStr: rr.data.noncestr, // 必填，生成签名的随机串
                                signature: rr.data.signature,// 必填，签名
                                jsApiList: [
                                    'onMenuShareTimeline',//分享朋友圈
                                    'onMenuShareAppMessage',//分享给好友
                                    'onMenuShareQQ',//分享到QQ
                                    'onMenuShareWeibo',//分享腾讯微博
                                ] // 必填，需要使用的JS接口列表
                            });
                            let tmp = {
                                title: '欢迎来到知行', // 分享标题
                                desc: '来知行,做兼职,快乐一下', // 分享描述
                                link: window.location.href+`?invite_code=${JSON.parse(localStorage.getItem('user')).invite_code}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                                imgUrl: 'http://m.zxskill.com/img/logo.png', // 分享图标
                            }
                            wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                                wx.onMenuShareTimeline(tmp, function (res) {
                                });
                                wx.onMenuShareAppMessage(tmp, function (res) {
                                });
                                wx.onMenuShareQQ(tmp, function (res) {
                                });
                                wx.onMenuShareWeibo(tmp, function (res) {
                                });
                            });
                        })
                    })
                }).catch(e => {
                    console.log(e)
                });

                if(this.$route.query.invite_code){
                    localStorage.setItem('invite_code',this.$route.query.invite_code)
                }
            }
        },
        watch: {
            $route() {
                this.init();
                this.routeName = this.$route.name;
                this.show_nav = this.$route.meta.show_nav

            },
        },

    }
</script>


<style lang="less">
    #app {
        min-height: 100%;
    }

    @import url('../public/css/common.less');
</style>
